<?php

/**
 * This is the model class for table "reklame_tarif".
 *
 * The followings are the available columns in table 'reklame_tarif':
 * @property string $id_tarif_rek
 * @property string $id_jenis_rek
 * @property string $id_kelas
 * @property string $golongan_kelas
 * @property double $nilai_sewa
 * @property double $njop
 * @property string $lama_pasang
 * @property string $sudut_pandang
 *
 * The followings are the available model relations:
 * @property ReklameJenis $idJenisRek
 * @property ReklameKelas $idKelas
 */
class ReklameTarif extends CActiveRecord
{
	public $golongan_kelas;
        public $jenis_rekening;
        /**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'reklame_tarif';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id_tarif_rek', 'required'),
			array('nilai_sewa, njop', 'numerical'),
			array('golongan_kelas', 'length', 'max'=>25),
			array('id_jenis_rek, id_kelas, lama_pasang, sudut_pandang', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id_tarif_rek, id_jenis_rek, id_kelas, golongan_kelas, nilai_sewa, njop, lama_pasang, sudut_pandang', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'idJenisRek' => array(self::BELONGS_TO, 'ReklameJenis', 'id_jenis_rek'),
			'idKelas' => array(self::BELONGS_TO, 'ReklameKelas', 'id_kelas'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id_tarif_rek' => 'Id Tarif Rek',
			'id_jenis_rek' => 'Id Jenis Rek',
			'id_kelas' => 'Id Kelas',
			'golongan_kelas' => 'Golongan Kelas',
			'nilai_sewa' => 'Nilai Sewa',
			'njop' => 'Njop',
			'lama_pasang' => 'Lama Pasang',
			'sudut_pandang' => 'Sudut Pandang',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;
                $criteria->alias="j";                
                $criteria->select = 'j.*, k.golongan_kelas, r.jenis_rekening ';
                $criteria->join = 'INNER JOIN reklame_kelas k ON k.id_kelas = j.id_kelas
                                  INNER JOIN reklame_jenis r ON j.id_jenis_rek = r.id_jenis_rek';
                
		$criteria->compare('id_tarif_rek',$this->id_tarif_rek,true);
		$criteria->compare('id_jenis_rek',$this->id_jenis_rek,true);
		$criteria->compare('id_kelas',$this->id_kelas,true);
		$criteria->compare('golongan_kelas',$this->golongan_kelas,true);
		$criteria->compare('nilai_sewa',$this->nilai_sewa);
		$criteria->compare('njop',$this->njop);
		$criteria->compare('lama_pasang',$this->lama_pasang,true);
		$criteria->compare('sudut_pandang',$this->sudut_pandang,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return ReklameTarif the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
